/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package VocSymbTest2;

/**
 *
 * @author StiggieBig
 */
public class GrammarRule implements Comparable<GrammarRule>{
    NonTerminal source;
    GrammarString target;
    
    //	default constructor
    
    <T extends VocabularySymbol> GrammarRule() {
        source = new NonTerminal();
        target = new GrammarString();
    }

    <T extends VocabularySymbol> GrammarRule(NonTerminal newSource, GrammarString newTarget) {
        source = new NonTerminal(newSource);
        target = new GrammarString(newTarget);
    }

    <T extends VocabularySymbol> GrammarRule(GrammarRule rhs){
    	source = new NonTerminal();
        target = new GrammarString();
        source = rhs.GetSource();
        target = rhs.GetTarget();
    }

    NonTerminal GetSource(){
    	NonTerminal nonTermOut;
    	nonTermOut = source;
    	return nonTermOut;
    }

    GrammarString GetTarget(){
    	GrammarString targetOut;
        targetOut = (GrammarString) target;
    	return targetOut;
    }

    void Print() {
        source.Print();
        System.out.print("->");
        target.Print();
        System.out.print(" ");
    }
    
    void PrintDebug(){
    	System.out.print("The source of the grammar rule is: ");
    	source.Print();
    	System.out.println("");
    	System.out.println("The target of the grammar rule is: ");
    	target.PrintDebug();
    	System.out.println("");
    }

    @Override
    public int compareTo(GrammarRule g) {
        
        int compVal = 0;
        compVal = source.compareTo(g.source);
        if(compVal == 0){
        	GrammarString targ1 , targ2; 
        	targ1 = target;
        	targ2 = g.GetTarget();
            compVal = targ1.compareTo(targ2);
        }
        return compVal;
    }
}